﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Company.Shell.Models;
using Company.Shell.Views;
using Microsoft.Extensions.DependencyInjection;
using System.Windows;

namespace Company.Shell.ViewModels
{
    public class ShellViewModel : ObservableObject //实现属性通知
    {
        /// <summary>
        /// 是否显示页面的遮罩层
        /// </summary>
        private Visibility show = Visibility.Collapsed;
        public Visibility Show 
        {
            get => show;
            set => SetProperty(ref show , value);//属性值变化时通知
        }   
        private object? content;
        /// <summary>
        /// 页面
        /// </summary>
        public object? Content
        {
            get => content;
            set => SetProperty(ref content, value);//属性值变化时通知
        }
        public ShellViewModel()
        {
           content = App.Current.Services.GetService<InitializeView>();//InitializeView作为初始页面

            //当硬件加载成功后，跳转到主页
            WeakReferenceMessenger.Default.Register<InitializeSuccessMessage>(this,(send,arg) =>
           {
               Content = App.Current.Services.GetService<MainView>();//将MainView注入到Content
               var window = App.Current.MainWindow;//获取当前应用的主窗口
               window.WindowState = WindowState.Normal;//将窗口状态设置为正常  
               window.Width = 1800;
               window.Height = 1000;
               SetWindow(window);


           });
        }

        private void SetWindow(Window window)
        {
            window.Left = (SystemParameters.WorkArea.Width - window.Width) / 2;
            window.Top = (SystemParameters.WorkArea.Height - window.Height) / 2;
        }
    }
}
